Skip to content

Conversation

DenisGZM
Copy link
Contributor

@DenisGZM DenisGZM commented Sep 12, 2025

Added declarations for nan/nanf so Clang could translate it to appropriate functions from libdevice

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels Sep 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 12, 2025

@llvm/pr-subscribers-clang

Author: Denis.G (DenisGZM)

Changes

Added declarations for nan/nanf so Clang could translate it to appropriate functions from libdevice


Full diff: https://github.com/llvm/llvm-project/pull/158301.diff

5 Files Affected:

  • (modified) clang/lib/Headers/__clang_cuda_libdevice_declares.h (+2-2)
  • (modified) clang/lib/Headers/__clang_cuda_math.h (+2)
  • (modified) clang/test/Headers/Inputs/include/math.h (+2)
  • (modified) clang/test/Headers/nvptx_device_cmath_functions.cpp (+4)
  • (modified) clang/test/Headers/nvptx_device_math_functions.cpp (+4)
diff --git a/clang/lib/Headers/__clang_cuda_libdevice_declares.h b/clang/lib/Headers/__clang_cuda_libdevice_declares.h
index ded0382a7ddce..cbc7f723ce8c4 100644
--- a/clang/lib/Headers/__clang_cuda_libdevice_declares.h
+++ b/clang/lib/Headers/__clang_cuda_libdevice_declares.h
@@ -269,8 +269,8 @@ __DEVICE__ float __nv_modff(float __a, float *__b);
 __DEVICE__ int __nv_mul24(int __a, int __b);
 __DEVICE__ long long __nv_mul64hi(long long __a, long long __b);
 __DEVICE__ int __nv_mulhi(int __a, int __b);
-__DEVICE__ double __nv_nan(const signed char *__a);
-__DEVICE__ float __nv_nanf(const signed char *__a);
+__DEVICE__ double __nv_nan(const char *__a);
+__DEVICE__ float __nv_nanf(const char *__a);
 __DEVICE__ double __nv_nearbyint(double __a);
 __DEVICE__ float __nv_nearbyintf(float __a);
 __DEVICE__ double __nv_nextafter(double __a, double __b);
diff --git a/clang/lib/Headers/__clang_cuda_math.h b/clang/lib/Headers/__clang_cuda_math.h
index 44c6e9a4e48d1..0d67ea309d272 100644
--- a/clang/lib/Headers/__clang_cuda_math.h
+++ b/clang/lib/Headers/__clang_cuda_math.h
@@ -201,6 +201,8 @@ __DEVICE__ int max(int __a, int __b) { return __nv_max(__a, __b); }
 __DEVICE__ int min(int __a, int __b) { return __nv_min(__a, __b); }
 __DEVICE__ double modf(double __a, double *__b) { return __nv_modf(__a, __b); }
 __DEVICE__ float modff(float __a, float *__b) { return __nv_modff(__a, __b); }
+__DEVICE__ float nanf(const char *__a) { return __nv_nanf(__a); }
+__DEVICE__ double nan(const char *__a) { return __nv_nan(__a); }
 __DEVICE__ double nearbyint(double __a) { return __builtin_nearbyint(__a); }
 __DEVICE__ float nearbyintf(float __a) { return __builtin_nearbyintf(__a); }
 __DEVICE__ double nextafter(double __a, double __b) {
diff --git a/clang/test/Headers/Inputs/include/math.h b/clang/test/Headers/Inputs/include/math.h
index cbd6bf7457a76..65f4395d6c966 100644
--- a/clang/test/Headers/Inputs/include/math.h
+++ b/clang/test/Headers/Inputs/include/math.h
@@ -107,6 +107,8 @@ long lround(double __a);
 long lroundf(float __a);
 double modf(double __a, double *__b);
 float modff(float __a, float *__b);
+float nanf(const char *__a);
+double nan(const char *__a);
 double nearbyint(double __a);
 float nearbyintf(float __a);
 double nextafter(double __a, double __b);
diff --git a/clang/test/Headers/nvptx_device_cmath_functions.cpp b/clang/test/Headers/nvptx_device_cmath_functions.cpp
index 898a8544a6e6a..04778210a2991 100644
--- a/clang/test/Headers/nvptx_device_cmath_functions.cpp
+++ b/clang/test/Headers/nvptx_device_cmath_functions.cpp
@@ -22,5 +22,9 @@ void test_sqrt(double a1) {
     double l4 = fabs(a1);
     // CHECK-YES: call noundef i32 @__nv_abs(i32
     double l5 = abs((int)a1);
+    // CHECK-YES: call noundef float @__nv_nanf(ptr noundef
+    float l6 = nanf("");
+    // CHECK-YES: call noundef double @__nv_nan(ptr noundef
+    double l7 = nan("");
   }
 }
diff --git a/clang/test/Headers/nvptx_device_math_functions.cpp b/clang/test/Headers/nvptx_device_math_functions.cpp
index 791cb49f918c7..d70f3d7dac582 100644
--- a/clang/test/Headers/nvptx_device_math_functions.cpp
+++ b/clang/test/Headers/nvptx_device_math_functions.cpp
@@ -22,5 +22,9 @@ void test_sqrt(double a1) {
     double l4 = fabs(a1);
     // CHECK-YES: call noundef i32 @__nv_abs(i32
     double l5 = abs((int)a1);
+    // CHECK-YES: call noundef float @__nv_nanf(ptr noundef
+    float l6 = nanf("");
+    // CHECK-YES: call noundef double @__nv_nan(ptr noundef
+    double l7 = nan("");
   }
 }

@llvmbot
Copy link
Member

llvmbot commented Sep 12, 2025

@llvm/pr-subscribers-backend-x86

Author: Denis.G (DenisGZM)

Changes

Added declarations for nan/nanf so Clang could translate it to appropriate functions from libdevice


Full diff: https://github.com/llvm/llvm-project/pull/158301.diff

5 Files Affected:

  • (modified) clang/lib/Headers/__clang_cuda_libdevice_declares.h (+2-2)
  • (modified) clang/lib/Headers/__clang_cuda_math.h (+2)
  • (modified) clang/test/Headers/Inputs/include/math.h (+2)
  • (modified) clang/test/Headers/nvptx_device_cmath_functions.cpp (+4)
  • (modified) clang/test/Headers/nvptx_device_math_functions.cpp (+4)
diff --git a/clang/lib/Headers/__clang_cuda_libdevice_declares.h b/clang/lib/Headers/__clang_cuda_libdevice_declares.h
index ded0382a7ddce..cbc7f723ce8c4 100644
--- a/clang/lib/Headers/__clang_cuda_libdevice_declares.h
+++ b/clang/lib/Headers/__clang_cuda_libdevice_declares.h
@@ -269,8 +269,8 @@ __DEVICE__ float __nv_modff(float __a, float *__b);
 __DEVICE__ int __nv_mul24(int __a, int __b);
 __DEVICE__ long long __nv_mul64hi(long long __a, long long __b);
 __DEVICE__ int __nv_mulhi(int __a, int __b);
-__DEVICE__ double __nv_nan(const signed char *__a);
-__DEVICE__ float __nv_nanf(const signed char *__a);
+__DEVICE__ double __nv_nan(const char *__a);
+__DEVICE__ float __nv_nanf(const char *__a);
 __DEVICE__ double __nv_nearbyint(double __a);
 __DEVICE__ float __nv_nearbyintf(float __a);
 __DEVICE__ double __nv_nextafter(double __a, double __b);
diff --git a/clang/lib/Headers/__clang_cuda_math.h b/clang/lib/Headers/__clang_cuda_math.h
index 44c6e9a4e48d1..0d67ea309d272 100644
--- a/clang/lib/Headers/__clang_cuda_math.h
+++ b/clang/lib/Headers/__clang_cuda_math.h
@@ -201,6 +201,8 @@ __DEVICE__ int max(int __a, int __b) { return __nv_max(__a, __b); }
 __DEVICE__ int min(int __a, int __b) { return __nv_min(__a, __b); }
 __DEVICE__ double modf(double __a, double *__b) { return __nv_modf(__a, __b); }
 __DEVICE__ float modff(float __a, float *__b) { return __nv_modff(__a, __b); }
+__DEVICE__ float nanf(const char *__a) { return __nv_nanf(__a); }
+__DEVICE__ double nan(const char *__a) { return __nv_nan(__a); }
 __DEVICE__ double nearbyint(double __a) { return __builtin_nearbyint(__a); }
 __DEVICE__ float nearbyintf(float __a) { return __builtin_nearbyintf(__a); }
 __DEVICE__ double nextafter(double __a, double __b) {
diff --git a/clang/test/Headers/Inputs/include/math.h b/clang/test/Headers/Inputs/include/math.h
index cbd6bf7457a76..65f4395d6c966 100644
--- a/clang/test/Headers/Inputs/include/math.h
+++ b/clang/test/Headers/Inputs/include/math.h
@@ -107,6 +107,8 @@ long lround(double __a);
 long lroundf(float __a);
 double modf(double __a, double *__b);
 float modff(float __a, float *__b);
+float nanf(const char *__a);
+double nan(const char *__a);
 double nearbyint(double __a);
 float nearbyintf(float __a);
 double nextafter(double __a, double __b);
diff --git a/clang/test/Headers/nvptx_device_cmath_functions.cpp b/clang/test/Headers/nvptx_device_cmath_functions.cpp
index 898a8544a6e6a..04778210a2991 100644
--- a/clang/test/Headers/nvptx_device_cmath_functions.cpp
+++ b/clang/test/Headers/nvptx_device_cmath_functions.cpp
@@ -22,5 +22,9 @@ void test_sqrt(double a1) {
     double l4 = fabs(a1);
     // CHECK-YES: call noundef i32 @__nv_abs(i32
     double l5 = abs((int)a1);
+    // CHECK-YES: call noundef float @__nv_nanf(ptr noundef
+    float l6 = nanf("");
+    // CHECK-YES: call noundef double @__nv_nan(ptr noundef
+    double l7 = nan("");
   }
 }
diff --git a/clang/test/Headers/nvptx_device_math_functions.cpp b/clang/test/Headers/nvptx_device_math_functions.cpp
index 791cb49f918c7..d70f3d7dac582 100644
--- a/clang/test/Headers/nvptx_device_math_functions.cpp
+++ b/clang/test/Headers/nvptx_device_math_functions.cpp
@@ -22,5 +22,9 @@ void test_sqrt(double a1) {
     double l4 = fabs(a1);
     // CHECK-YES: call noundef i32 @__nv_abs(i32
     double l5 = abs((int)a1);
+    // CHECK-YES: call noundef float @__nv_nanf(ptr noundef
+    float l6 = nanf("");
+    // CHECK-YES: call noundef double @__nv_nan(ptr noundef
+    double l7 = nan("");
   }
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants